package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名：");
        String className = scanner.nextLine();

        Class cls = Class.forName(className);
        Object o = cls.newInstance();
        Method[] methods = cls.getDeclaredMethods();
        if (cls.isAnnotationPresent(AutoRunClass.class)) {
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)) {
                    AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                    int value = arm.value();//获取名为value参数的值
                    System.out.println("执行方法：" + method.getName()+"()"+value+"次");
                    for (int i = 0; i < value; i++) {
                        method.invoke(o);
                    }
                }
            }
        }else {
            System.out.println(className+"该类没有被@AutoRunClass所标注");
        }
    }
}
